package org.maven.utils.zookeeper;

import org.apache.curator.test.TestingCluster;
import org.apache.log4j.Logger;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
import org.apache.zookeeper.server.quorum.QuorumPeerMain;

import com.kevin.utility.common.ResourceUtil;

public class ZookeeperServerCluster1 {
	static Logger logger = Logger.getLogger(ZookeeperServerCluster1.class);

	public static void main(String[] args) {
		startZK();
	}

	public static void startTestingCluster() {
		TestingCluster cluster = new TestingCluster(3);
		try {
			cluster.start();
			Thread.currentThread().wait(Long.MAX_VALUE);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		} finally {
			try {
				cluster.close();
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
			}
		}
	}

	public static void startZK() {
		QuorumPeerMain main = new QuorumPeerMain();
		QuorumPeerConfig config = new QuorumPeerConfig();
		try {
			config.parse(ResourceUtil.getPath("") + "\\src\\main\\resources\\zookeeper\\conf\\zookeeper1\\zoo.cfg");
			main.runFromConfig(config);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		

	}

}
